﻿<UserControl x:Class="XWord.GUI.Views.Fundamental.EtymaLibraryExplorerView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:cal="http://www.caliburnproject.org"
             xmlns:inf="http://www.grandsys.com/luna"
             xmlns:info="http://schemas.xword.com/winfx/xaml/info"
             xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <ContextMenu x:Key="EtymaMenu"  cal:Action.TargetWithoutContext="{Binding PlacementTarget.Tag,RelativeSource={RelativeSource Mode=Self}}">
            <!--<MenuItem Header="复制到搜索框" cal:Message.Attach="CopyWordToSearch"  />-->
            <MenuItem Header="编辑" cal:Message.Attach="OpenEditDialog"  />
        </ContextMenu>
    </UserControl.Resources>
    <inf:DockingWindowMetadata.Instance>
        <inf:DockingWindowMetadata  Title="{Binding DisplayName}" IsToolWindow="True" DefaultDock="Right"
                                    CanClose="False" CreateNewDockingGroup="True" />
    </inf:DockingWindowMetadata.Instance>
    <ListBox ItemsSource="{Binding EtymaLibraryList}"
             SelectedItem="{Binding SelectedItem}"
             x:Name="Element_EtymaLibraryList"
             cal:Message.Attach="[Event Drop] = [Action AddEtyma($eventArgs.Data)]">
        <info:MaskAttach.Content>
            <info:MaskAttach Open="{Binding IsOpen}" DataContext="{Binding DataContext,ElementName=Element_EtymaLibraryList}">
                <info:MaskAttach.Template>
                    <DataTemplate>
                        <Border Background="Silver" Opacity="0.7">
                            <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center"
                                       Foreground="SteelBlue"
                                       FontSize="16"
                                       Text="{Binding EtymaTip}"/>
                        </Border>
                    </DataTemplate>
                </info:MaskAttach.Template>
            </info:MaskAttach>
        </info:MaskAttach.Content>
        <ListBox.ItemTemplate>
            <DataTemplate>
                <TextBlock HorizontalAlignment="Left" Tag="{Binding DataContext,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=ListBox}}" Text="{Binding Name}" ToolTip="{Binding Comment}">
                    <TextBlock.ContextMenu>
                        <ContextMenu 
                            cal:Action.TargetWithoutContext="{Binding PlacementTarget.Tag, RelativeSource={RelativeSource Mode=Self}}">
                            <MenuItem Header="详细" cal:Message.Attach="OpenEtymaDetail($dataContext)"></MenuItem>
                            <MenuItem Header="编辑" cal:Message.Attach="OpenEditDialog"  />
                        </ContextMenu>
                    </TextBlock.ContextMenu>
                </TextBlock>
            </DataTemplate>
        </ListBox.ItemTemplate>
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="SelectionChanged">
                <info:ReadOnlyPropertyAction Property="SelectedItem" BindablePropertyItem="{Binding SelectedItem, Mode=TwoWay}"/>
            </i:EventTrigger>
        </i:Interaction.Triggers>
    </ListBox>
</UserControl>
<!--cal:Message.Attach="[Event SelectionChanged] = [Action SearchEtymaWord($this.SelectedItem.Name)];
                                 [Event KeyDown] = [Action SearchEtymaByKey(0,$eventArgs)]"-->